/**   
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: DictionaryController.java 
 * @Prject: LianniuMgrSer
 * @Package: com.lianniu.web.baseService.dict.controller
 * @Description: TODO

 * @date: 2016年3月31日 上午9:36:28 
 * @version: V1.0   
 */
package com.lianniu.web.baseService.dict.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.baseService.dict.model.DictionaryVo;
import com.lianniu.web.baseService.dict.service.IDictionaryService;
import com.lianniu.web.pagination.PaginationInfo;
import com.lianniu.web.util.StringUtil;

/** 
 * @ClassName: DictionaryController 
 * @Description: TODO

 * @date: 2016年3月31日 上午9:36:28  
 */
@Controller
@RequestMapping("/rest/dictionary")
public class DictionaryRestController {
  
 private final static Logger logger = Logger.getLogger(DictionaryRestController.class);
  
  @Autowired
  private  IDictionaryService dictionaryService;
  
 /**
  * 
  * @Title: dictionaryList 
  * @Description: TODO

  * @param request
  * @param curVo
  * @param paginationInfo
  * @return
  * @date: 2016年4月2日 下午10:19:50 
  * @return: BaseResult
  */
  @RequestMapping(value="/dictionaryList",method={RequestMethod.GET,RequestMethod.POST})
  public @ResponseBody BaseResult dictionaryList(HttpServletRequest request,DictionaryVo curVo,PaginationInfo paginationInfo)
  {
       logger.info("DictionaryRestController dictionaryList begin.");
       try {
           
           logger.info("dictionaryList begin.");          
           BaseResult baseResult = dictionaryService.selectByDictName(curVo, paginationInfo);
           logger.info("dictionaryList end.");
           logger.info("DictionaryRestController dictionaryList end.");
           return baseResult;
       } catch (Exception e) {
       logger.error("DictionaryRestController dictionaryList error:" + e.getMessage());
       logger.error("DictionaryRestController dictionaryList end.");
       return BaseResult.exception(e.getMessage());
     }
  }
  
/**
 * 
 * @Title: dictionaryAdd 
 * @Description: TODO

 * @param request
 * @param curVo
 * @return
 * @date: 2016年4月2日 下午10:21:49 
 * @return: BaseResult
 */
  @RequestMapping(value = {"/dictionaryAdd"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictionaryAdd(HttpServletRequest request,DictionaryVo curVo) {
      logger.info("DictionaryRestController dictionaryAdd begin.");      
      logger.info("DictionaryRestController dictionaryAdd:"+ JSON.toJSONString(curVo));
      try {
          logger.info("dictionaryAdd begin.");
          curVo.setId(StringUtil.getUUID());
          BaseResult baseResult = dictionaryService.insertDictionary(curVo);
          logger.info("dictionaryAdd baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictionaryAdd end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("dictionaryAdd error:"+e.getMessage());
      logger.info("DictionaryRestController dictionaryAdd end.");
      return BaseResult.exception(e.getMessage());
    }

  }
  
 /**
 * 
 * @Title: dictionaryEdit 
 * @Description: TODO

 * @param request
 * @param curVo
 * @return
 * @date: 2016年4月2日 下午10:23:58 
 * @return: BaseResult
 */
  @RequestMapping(value = {"/dictionaryEdit"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictionaryEdit(HttpServletRequest request,DictionaryVo curVo) {
      logger.info("DictionaryRestController dictionaryEdit begin.");      
      logger.info("DictionaryRestController dictionaryEdit:"+ JSON.toJSONString(curVo));
      try {
          logger.info("dictionaryEdit begin.");
          BaseResult baseResult = dictionaryService.updateById(curVo);
          logger.info("dictionaryEdit baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictionaryEdit end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("dictionaryEdit error:"+e.getMessage());
      logger.info("DictionaryRestController dictionaryEdit end.");
      return BaseResult.exception(e.getMessage());
    }
  }  
  
/**
 * 
 * @Title: selectDictionaryById 
 * @Description: TODO

 * @param request
 * @param curVo
 * @return
 * @date: 2016年4月5日 下午4:20:45 
 * @return: BaseResult
 */
  @RequestMapping(value="/selectDictionaryById",method={RequestMethod.GET,RequestMethod.POST})
  public @ResponseBody BaseResult selectDictionaryById(HttpServletRequest request,DictionaryVo curVo) {
        logger.info("DictionaryRestController selectDictionaryById begin.");
        try {
                    
          BaseResult baseResult = dictionaryService.selectById(curVo);
          logger.info("selectDictionaryById end.");
          logger.info("DictionaryRestController selectDictionaryById end.");
          return baseResult;
        } catch (Exception e) {
          logger.error("DictionaryRestController selectDictionaryById error:" + e.getMessage());
          logger.error("DictionaryRestController selectDictionaryById end.");
          return BaseResult.exception(e.getMessage());
        }
  } 
  
  /***
   * 
   * @Title: dictionaryDel 
   * @Description: TODO

   * @param request
   * @return
   * @date: 2016年4月5日 下午4:20:49 
   * @return: BaseResult
   */
  @RequestMapping(value = {"/dictionaryDel"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictionaryDel(HttpServletRequest request) {
      logger.info("DictionaryRestController dictionaryDel begin.");
     try {          
          logger.info("dictionaryDel begin.");
          BaseResult baseResult = dictionaryService.deleteDictionaryBatch(request.getParameter("ids").split(","));
          logger.info("dictionaryDel baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictionaryDel end.");
          
          logger.info("DictionaryRestController dictionaryDel end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("DictionaryRestController dictionaryDel error:" + e.getMessage());
      logger.info("DictionaryRestController dictionaryDel end.");
      return BaseResult.exception(e.getMessage());
    }

  }
  
  /**
   * 
   * @Title: dictionaryDelBatchLogic 
   * @Description: TODO

   * @param request
   * @return
   * @date: 2016年4月9日 下午7:43:28 
   * @return: BaseResult
   */
  @RequestMapping(value = {"/dictionaryDelBatchLogic"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult dictionaryDelBatchLogic(HttpServletRequest request) {
      logger.info("DictTypeRestController dictionaryDelBatchLogic begin.");
     try {          
          logger.info("dictionaryDelBatchLogic begin.");
          BaseResult baseResult = dictionaryService.delBatchDictionaryLogic(request.getParameter("updateUser"),request.getParameter("ids").split(","));
          logger.info("dictionaryDelBatchLogic baseResult:" + JSON.toJSONString(baseResult));
          logger.info("dictionaryDelBatchLogic end.");
          
          logger.info("DictionaryRestController dictionaryDelBatchLogic end.");
          return baseResult;

    } catch (Exception e) {
      logger.error("DictionaryRestController dictionaryDelBatchLogic error:" + e.getMessage());
      logger.info("DictionaryRestController dictionaryDelBatchLogic end.");
      return BaseResult.exception(e.getMessage());
    }

  }
  
  /**
   * 
   * @Title: checkDicName 
   * @Description: TODO

   * @param request
   * @return
   * @date: 2016年4月7日 上午8:36:07 
   * @return: Boolean
   */
  @RequestMapping(value = {"/checkDicName"}, method = RequestMethod.POST)
  public @ResponseBody Boolean checkDicName(HttpServletRequest request,DictionaryVo curVo) {
      Boolean flag=true;
      logger.info("DictionaryRestController checkDicName begin.");
     try {          
          logger.info("checkDicName begin.");
          
          if(("".equalsIgnoreCase(curVo.getDicName())||curVo.getDicName()==null))
          {
            return true;
          }        
          flag = dictionaryService.checkDicName(curVo);
          logger.info("checkDicName end.");
          
          logger.info("DictionaryRestController checkDicName end.");
          return flag;
    } catch (Exception e) {
      logger.error("DictionaryRestController checkDicName error:" + e.getMessage());
      logger.info("DictionaryRestController checkDicName end.");
      return flag;
    }
  }

  /**
   * 
   * @Title: checkDicNameEdit 
   * @Description: TODO

   * @param request
   * @param curVo
   * @return
   * @date: 2016年4月7日 上午10:11:32 
   * @return: Boolean
   */
  @RequestMapping(value = {"/checkDicNameEdit"}, method = RequestMethod.POST)
  public @ResponseBody Boolean checkDicNameEdit(HttpServletRequest request,DictionaryVo curVo) {
      Boolean flag=true;
      logger.info("DictionaryRestController checkDicName begin.");
     try {          
          logger.info("checkDicName begin.");
          
          if(("".equalsIgnoreCase(curVo.getDicName())||curVo.getDicName()==null))
          {
            return flag;
          }        
          DictionaryVo vo=(DictionaryVo)dictionaryService.selectById(curVo).getData();
          if((vo.getTypeId().equals(curVo.getTypeId()))&&(vo.getDicName().equals(curVo.getDicName())))
          {return flag;}
          
          flag = dictionaryService.checkDicName(curVo);
          logger.info("checkDicName end.");
          
          logger.info("DictionaryRestController checkDicName end.");
          return flag;
    } catch (Exception e) {
      logger.error("DictionaryRestController checkDicName error:" + e.getMessage());
      logger.info("DictionaryRestController checkDicName end.");
      return flag;
    }
  }
  
  /**
   * 
   * @Title: checkDicValue 
   * @Description: TODO

   * @param request
   * @return
   * @date: 2016年4月7日 上午8:36:15 
   * @return: Boolean
   */
  @RequestMapping(value = {"/checkDicValue"}, method = RequestMethod.POST)
  public @ResponseBody Boolean checkDicValue(HttpServletRequest request,DictionaryVo curVo) {
      Boolean flag=true;
      logger.info("DictionaryRestController checkDicValue begin.");
     try {          
          logger.info("checkDicValue begin.");   
          if(("".equalsIgnoreCase(curVo.getDicValue())||curVo.getDicValue()==null))
          {
            return true;
          }             
          flag = dictionaryService.checkDicValue(curVo);         
          logger.info("checkDicValue end.");
          
          logger.info("DictionaryRestController checkDicValue end.");
          return flag;
    } catch (Exception e) {
      logger.error("DictionaryRestController checkDicValue error:" + e.getMessage());
      logger.info("DictionaryRestController checkDicValue end.");
      return flag;
    }

  }
  
  /**
   * 
   * @Title: checkDicValueEdit 
   * @Description: TODO

   * @param request
   * @param curVo
   * @return
   * @date: 2016年4月7日 上午10:22:10 
   * @return: Boolean
   */
  @RequestMapping(value = {"/checkDicValueEdit"}, method = RequestMethod.POST)
  public @ResponseBody Boolean checkDicValueEdit(HttpServletRequest request,DictionaryVo curVo) {
      Boolean flag=true;
      logger.info("DictionaryRestController checkDicValueEdit begin.");
     try {          
          logger.info("checkDicValueEdit begin.");   
          if(("".equalsIgnoreCase(curVo.getDicValue())||curVo.getDicValue()==null))
          {
            return true;
          }   
          DictionaryVo vo=(DictionaryVo)dictionaryService.selectById(curVo).getData();
          if((vo.getTypeId().equals(curVo.getTypeId()))&&(vo.getDicValue().equals(curVo.getDicValue())))
          {return flag;}
          flag = dictionaryService.checkDicValue(curVo);         
          logger.info("checkDicValueEdit end.");
          
          logger.info("DictionaryRestController checkDicValueEdit end.");
          return flag;
    } catch (Exception e) {
      logger.error("DictionaryRestController checkDicValueEdit error:" + e.getMessage());
      logger.info("DictionaryRestController checkDicValueEdit end.");
      return flag;
    }

  }

  
  @RequestMapping(value="/getDicNameValue",method={RequestMethod.GET,RequestMethod.POST})
  public @ResponseBody BaseResult getDicNameValue(HttpServletRequest request,DictionaryVo curVo)
  {
       logger.info("DictionaryRestController getDicNameValue begin.");
       try {
           
           logger.info("getDicNameValue begin.");          
           BaseResult baseResult = dictionaryService.selectDictionaryByDicType(curVo);
           logger.info("getDicNameValue end.");
           logger.info("DictionaryRestController getDicNameValue end.");
           return baseResult;
       } catch (Exception e) {
       logger.error("DictionaryRestController getDicNameValue error:" + e.getMessage());
       logger.error("DictionaryRestController getDicNameValue end.");
       return BaseResult.exception(e.getMessage());
     }
  }
  
}
